from app.core.crud import CRUDBase
from app.models.idiom import Idiom
from app.schemas.idiom import IdiomCreate, IdiomUpdate


class IdiomController(CRUDBase[Idiom, IdiomCreate, IdiomUpdate]):
    def __init__(self):
        super().__init__(model=Idiom)

    async def is_exist(self, word: str) -> bool:
        return await self.model.filter(word=word).exists()

    async def update_Idiom(self, idiom_id: int, obj_in: IdiomUpdate):
        idiom = await self.model.get(id=idiom_id)
        idiom.word = obj_in.word
        # poetry.rhythmic = obj_in.rhythmic
        # poetry.categoryCode = obj_in.categoryCode
        # poetry.desc = obj_in.desc
        # poetry.author = obj_in.author
        # poetry.paragraphs = obj_in.paragraphs
        # poetry.notes = obj_in.notes
        # poetry.section = obj_in.section
        await Idiom.save()

    async def create_bulk(self, obj_list: list[IdiomCreate]):
        await self.model.bulk_create([self.model(**obj.dict()) for obj in obj_list])


idiom_controller = IdiomController()
